package cn.itsource.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.itsource.constants.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义权限加载接口实现类
 */
@Slf4j
public class StpInterfaceImpl implements StpInterface {

    private RedisTemplate<Object,Object> redisTemplate ;

    //构造参数
    public StpInterfaceImpl(RedisTemplate<Object,Object> redisTemplate){
        this.redisTemplate = redisTemplate;
    }


    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {

        //去redis加载用户的权限
        String perKey = String.format(Constants.Redis.KEY_PREFIX_PERMISSIONS, loginId);
        List<String> permissions = (List<String>) redisTemplate.opsForValue().get(perKey);
        log.info("权限校验 - 从缓存加载权限列表 {}",permissions);
        return permissions;
    }



    //返回一个账号所拥有的角色标识集合
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return new ArrayList<String>();
    }

}
